@extends('admin.layout')

@section('title', '菜品详情')

@section('content')
<div class="space-y-6">
    <!-- 返回按钮 -->
    <div class="flex items-center">
        <a href="{{ route('admin.dishes.index') }}" 
           class="inline-flex items-center text-sm font-medium text-gray-500 hover:text-gray-700">
            <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"></path>
            </svg>
            返回菜品列表
        </a>
    </div>

    <!-- 菜品详情 -->
    <div class="bg-white shadow-lg rounded-xl border border-gray-100">
        <div class="px-6 py-6 border-b border-gray-200">
            <div class="flex items-center justify-between">
                <div class="flex items-center">
                    <div class="flex-shrink-0 h-16 w-16">
                        @if($dish->image)
                            <img class="h-16 w-16 rounded-lg object-cover" src="{{ $dish->image }}" alt="{{ $dish->name }}">
                        @else
                            <div class="h-16 w-16 rounded-lg bg-gray-200 flex items-center justify-center">
                                <svg class="h-8 w-8 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
                                </svg>
                            </div>
                        @endif
                    </div>
                    <div class="ml-4">
                        <h1 class="text-2xl font-semibold text-gray-900">{{ $dish->name }}</h1>
                        <p class="text-sm text-gray-600">{{ $dish->category->name ?? '未分类' }}</p>
                    </div>
                </div>
                <div class="flex items-center space-x-3">
                    @if($dish->is_available)
                        <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800">
                            <svg class="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 8 8">
                                <circle cx="4" cy="4" r="3"/>
                            </svg>
                            可用
                        </span>
                    @else
                        <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-red-100 text-red-800">
                            <svg class="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 8 8">
                                <circle cx="4" cy="4" r="3"/>
                            </svg>
                            不可用
                        </span>
                    @endif
                    @if($dish->is_featured)
                        <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800">
                            <svg class="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 8 8">
                                <circle cx="4" cy="4" r="3"/>
                            </svg>
                            推荐
                        </span>
                    @endif
                </div>
            </div>
        </div>

        <div class="px-6 py-6">
            <!-- 基本信息 -->
            <div class="grid grid-cols-1 gap-6 sm:grid-cols-2">
                <div>
                    <h3 class="text-lg font-medium text-gray-900 mb-4">基本信息</h3>
                    <dl class="space-y-3">
                        <div>
                            <dt class="text-sm font-medium text-gray-500">菜品名称</dt>
                            <dd class="text-sm text-gray-900">{{ $dish->name }}</dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">分类</dt>
                            <dd class="text-sm text-gray-900">{{ $dish->category->name ?? '未分类' }}</dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">价格</dt>
                            <dd class="text-sm text-gray-900">¥{{ number_format($dish->price, 2) }}</dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">制作时间</dt>
                            <dd class="text-sm text-gray-900">{{ $dish->cooking_time ? $dish->cooking_time . '分钟' : '未设置' }}</dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">排序权重</dt>
                            <dd class="text-sm text-gray-900">{{ $dish->sort_order }}</dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">创建时间</dt>
                            <dd class="text-sm text-gray-900">{{ $dish->created_at->format('Y-m-d H:i:s') }}</dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">更新时间</dt>
                            <dd class="text-sm text-gray-900">{{ $dish->updated_at->format('Y-m-d H:i:s') }}</dd>
                        </div>
                    </dl>
                </div>

                <div>
                    <h3 class="text-lg font-medium text-gray-900 mb-4">详细信息</h3>
                    <dl class="space-y-3">
                        <div>
                            <dt class="text-sm font-medium text-gray-500">描述</dt>
                            <dd class="text-sm text-gray-900">{{ $dish->description ?: '暂无描述' }}</dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">标签</dt>
                            <dd class="text-sm text-gray-900">
                                @php
                                    $tags = is_array($dish->tags) ? $dish->tags : (is_string($dish->tags) ? json_decode($dish->tags, true) : []);
                                    $tags = $tags ?: [];
                                @endphp
                                @if(!empty($tags))
                                    <div class="flex flex-wrap gap-1">
                                        @foreach($tags as $tag)
                                            <span class="inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-blue-100 text-blue-800">
                                                {{ $tag }}
                                            </span>
                                        @endforeach
                                    </div>
                                @else
                                    暂无标签
                                @endif
                            </dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">口味</dt>
                            <dd class="text-sm text-gray-900">
                                @php
                                    $flavors = is_array($dish->flavors) ? $dish->flavors : (is_string($dish->flavors) ? json_decode($dish->flavors, true) : []);
                                    $flavors = $flavors ?: [];
                                @endphp
                                @if(!empty($flavors))
                                    <div class="flex flex-wrap gap-1">
                                        @foreach($flavors as $flavor)
                                            <span class="inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-green-100 text-green-800">
                                                {{ $flavor }}
                                            </span>
                                        @endforeach
                                    </div>
                                @else
                                    暂无口味信息
                                @endif
                            </dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">菜品来源</dt>
                            <dd class="text-sm text-gray-900">
                                @switch($dish->dish_source)
                                    @case('system')
                                        <span class="inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-purple-100 text-purple-800">
                                            系统菜品
                                        </span>
                                        @break
                                    @case('user')
                                        <span class="inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-blue-100 text-blue-800">
                                            用户创建
                                        </span>
                                        @break
                                    @case('menu')
                                        <span class="inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-green-100 text-green-800">
                                            菜单菜品
                                        </span>
                                        @break
                                    @default
                                        <span class="inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-gray-100 text-gray-800">
                                            未知来源
                                        </span>
                                @endswitch
                            </dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">创建者</dt>
                            <dd class="text-sm text-gray-900">{{ $dish->creator->nickname ?? '系统' }}</dd>
                        </div>
                        <div>
                            <dt class="text-sm font-medium text-gray-500">所属菜单</dt>
                            <dd class="text-sm text-gray-900">
                                @if($dish->menu)
                                    <a href="{{ route('admin.menus.show', $dish->menu) }}" class="text-indigo-600 hover:text-indigo-900">
                                        {{ $dish->menu->name }}
                                    </a>
                                @else
                                    无
                                @endif
                            </dd>
                        </div>
                    </dl>
                </div>
            </div>
        </div>
    </div>

    <!-- 使用情况 -->
    @if($dish->menu && $dish->menu->rooms)
    <div class="bg-white shadow-lg rounded-xl border border-gray-100">
        <div class="px-6 py-6 border-b border-gray-200">
            <div class="flex items-center">
                <svg class="w-6 h-6 text-indigo-600 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"></path>
                </svg>
                <h2 class="text-xl font-semibold text-gray-900">使用情况</h2>
            </div>
            <p class="mt-2 text-sm text-gray-600">该菜品在以下房间中使用</p>
        </div>

        <div class="px-6 py-6">
            @if($dish->menu->rooms->count() > 0)
            <div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
                @foreach($dish->menu->rooms as $room)
                <div class="bg-gray-50 rounded-lg p-4">
                    <div class="flex items-center justify-between">
                        <div>
                            <h3 class="text-sm font-medium text-gray-900">{{ $room->title }}</h3>
                            <p class="text-xs text-gray-500">房间ID: {{ $room->room_id }}</p>
                        </div>
                        <div class="text-right">
                            <span class="inline-flex items-center px-2 py-1 rounded text-xs font-medium 
                                {{ $room->status === 'active' ? 'bg-green-100 text-green-800' : 
                                   ($room->status === 'closed' ? 'bg-gray-100 text-gray-800' : 'bg-red-100 text-red-800') }}">
                                {{ $room->status === 'active' ? '活跃' : 
                                   ($room->status === 'closed' ? '已关闭' : '已过期') }}
                            </span>
                        </div>
                    </div>
                </div>
                @endforeach
            </div>
            @else
            <div class="text-center py-8">
                <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"></path>
                </svg>
                <h3 class="mt-2 text-sm font-medium text-gray-900">暂无使用</h3>
                <p class="mt-1 text-sm text-gray-500">该菜品目前没有在任何房间中使用</p>
            </div>
            @endif
        </div>
    </div>
    @endif

    <!-- 操作按钮 -->
    <div class="flex justify-end space-x-3">
        <a href="{{ route('admin.dishes.edit', $dish) }}" 
           class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
            <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
            </svg>
            编辑菜品
        </a>
    </div>
</div>
@endsection
